'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), controller.user.login);
  } else {
    router.post('/api/user/login', controller.user.login);
  }
  // 会员
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);
  // role
  router.get('/api/role/list', controller.role.allList);
  router.resources('role', '/api/role', controller.role);

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);

  // notice
  router.get('/api/notice/list', controller.notice.allList);
  router.resources('notice', '/api/notice', controller.notice);

  // news
  router.get('/api/news/list', controller.news.allList);
  router.resources('news', '/api/news', controller.news);
  // post
  router.get('/api/post/list', controller.post.allList);
  router.resources('post', '/api/post', controller.post);
  // comment
  router.get('/api/comment/list', controller.comment.allList);
  router.resources('comment', '/api/comment', controller.comment);
  // collect
  router.get('/api/collect/list', controller.collect.allList);
  router.resources('collect', '/api/collect', controller.collect);
  // like
  router.get('/api/like/list', controller.like.allList);
  router.resources('like', '/api/like', controller.like);

  // 题库管理
  router.get('/api/question/list', controller.question.allList);
  router.resources('question', '/api/question', controller.question);
  // 题库管理
  router.get('/api/questionOption/list', controller.questionOption.allList);
  router.resources('questionOption', '/api/questionOption', controller.questionOption);
  router.get('/api/answer/list', controller.answer.allList);
  router.resources('answer', '/api/answer', controller.answer);
};
